Add modulo operators to lexer
Tokens MODULO and SLASH_MODULO are going to represent the modulo and fmod operations on integers and floats, or return a pair with the divisor and the modulo, respectively.
This commit is contained in:
		
							parent
							
								
									4178bfefea
								
							
						
					
					
						commit
						9e1ef93990
					
				
					 1 changed files with 6 additions and 0 deletions
				
			
		|  | @ -37,6 +37,8 @@ const ( | ||||||
| 	SLASH | 	SLASH | ||||||
| 	SLASH_DOT | 	SLASH_DOT | ||||||
| 	SLASH_UNDERSCORE | 	SLASH_UNDERSCORE | ||||||
|  | 	SLASH_MODULO | ||||||
|  | 	MODULO | ||||||
| 
 | 
 | ||||||
| 	// Literals | 	// Literals | ||||||
| 	IDENTIFIER | 	IDENTIFIER | ||||||
|  | @ -179,6 +181,8 @@ func (l *Lexer) scanToken() { | ||||||
| 		} else { | 		} else { | ||||||
| 			l.addSimpleToken(GREATER) | 			l.addSimpleToken(GREATER) | ||||||
| 		} | 		} | ||||||
|  | 	case '%': | ||||||
|  | 		l.addSimpleToken(MODULO) | ||||||
| 	case '/': | 	case '/': | ||||||
| 		if l.match('/') { | 		if l.match('/') { | ||||||
| 			// A comment goes until the end of the line | 			// A comment goes until the end of the line | ||||||
|  | @ -211,6 +215,8 @@ func (l *Lexer) scanToken() { | ||||||
| 			l.addSimpleToken(SLASH_DOT) | 			l.addSimpleToken(SLASH_DOT) | ||||||
| 		} else if l.match('_') { | 		} else if l.match('_') { | ||||||
| 			l.addSimpleToken(SLASH_UNDERSCORE) | 			l.addSimpleToken(SLASH_UNDERSCORE) | ||||||
|  | 		} else if l.match('%') { | ||||||
|  | 			l.addSimpleToken(SLASH_MODULO) | ||||||
| 		} else { | 		} else { | ||||||
| 			l.addSimpleToken(SLASH) | 			l.addSimpleToken(SLASH) | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 Petar Kapriš
						Petar Kapriš