node/lib/metasm/metasm/parse.rb
def parse_value(lexer)
			nil while tok = lexer.readtok and tok.type == :space
			return if not tok
			case tok.type
			when :string
				# ignores the 'offset' word if followed by a string
				if not tok.value and tok.raw.downcase == 'offset'
					nil while ntok = lexer.readtok and ntok.type == :space
					if ntok.type == :string; tok = ntok
					else lexer.unreadtok ntok
					end
				end
				parse_intfloat(lexer, tok)
				val = tok.value || tok.raw
			when :quoted
				if tok.raw[0] != ?'
					lexer.unreadtok tok
					return
				end
				s = tok.value || tok.raw[1..-2]	# raise tok, 'need ppcessing !'
				s = s.reverse if lexer.respond_to? :program and lexer.program and lexer.program.cpu and lexer.program.cpu.endianness == :little
				val = s.unpack('C*').inject(0) { |sum, c| (sum << 8) | c }
			when :punct
				case tok.raw
				when '('
					nil while ntok = lexer.readtok and (ntok.type == :space or ntok.type == :eol)
					lexer.unreadtok ntok
					val = parse(lexer)
					nil while ntok = lexer.readtok and (ntok.type == :space or ntok.type == :eol)
					raise tok, "syntax error, no ) found after #{val.inspect}, got #{ntok.inspect}" if not ntok or ntok.type != :punct or ntok.raw != ')'
				when '!', '+', '-', '~'
					nil while ntok = lexer.readtok and (ntok.type == :space or ntok.type == :eol)
					lexer.unreadtok ntok
					raise tok, 'need expression after unary operator' if not val = parse_value(lexer)
					val = Expression[tok.raw.to_sym, val]
				when '.'
					parse_intfloat(lexer, tok)
					if not tok.value
						lexer.unreadtok tok
						return
					end
					val = tok.value
				else
					lexer.unreadtok tok
					return
				end
			else
				lexer.unreadtok tok
				return
			end
			nil while tok = lexer.readtok and tok.type == :space
			lexer.unreadtok tok
			val
		end
# returns the next value from lexer (parenthesised expression, immediate, variable, unary operators)
returns the next value from lexer (parenthesised expression, immediate, variable, unary operators)
returns the next value from lexer ( parenthesised expression immediate variable unary operators )
def parse_value(lexer)
			nil while tok = lexer.readtok and tok.type == :space
			return if not tok
			case tok.type
			when :string
				if not tok.value and tok.raw.downcase == 'offset'
					nil while ntok = lexer.readtok and ntok.type == :space
					if ntok.type == :string; tok = ntok
					else lexer.unreadtok ntok
					end
				end
				parse_intfloat(lexer, tok)
				val = tok.value || tok.raw
			when :quoted
				if tok.raw[0] != ?'
					lexer.unreadtok tok
					return
				end
				s = tok.value || tok.raw[1..-2]	
				s = s.reverse if lexer.respond_to? :program and lexer.program and lexer.program.cpu and lexer.program.cpu.endianness == :little
				val = s.unpack('C*').inject(0) { |sum, c| (sum << 8) | c }
			when :punct
				case tok.raw
				when '('
					nil while ntok = lexer.readtok and (ntok.type == :space or ntok.type == :eol)
					lexer.unreadtok ntok
					val = parse(lexer)
					nil while ntok = lexer.readtok and (ntok.type == :space or ntok.type == :eol)
					raise tok, "syntax error, no ) found after #{val.inspect}, got #{ntok.inspect}" if not ntok or ntok.type != :punct or ntok.raw != ')'
				when '!', '+', '-', '~'
					nil while ntok = lexer.readtok and (ntok.type == :space or ntok.type == :eol)
					lexer.unreadtok ntok
					raise tok, 'need expression after unary operator' if not val = parse_value(lexer)
					val = Expression[tok.raw.to_sym, val]
				when '.'
					parse_intfloat(lexer, tok)
					if not tok.value
						lexer.unreadtok tok
						return
					end
					val = tok.value
				else
					lexer.unreadtok tok
					return
				end
			else
				lexer.unreadtok tok
				return
			end
			nil while tok = lexer.readtok and tok.type == :space
			lexer.unreadtok tok
			val
		end
def parse_value ( lexer ) nil while tok = lexer . readtok and tok . type == :space return if not tok case tok . type when :string if not tok . value and tok . raw . downcase == 'offset' nil while ntok = lexer . readtok and ntok . type == :space if ntok . type == :string ; tok = ntok else lexer . unreadtok ntok end end parse_intfloat ( lexer , tok ) val = tok . value || tok . raw when :quoted if tok . raw [ 0 ] != ?' lexer . unreadtok tok return end s = tok . value || tok . raw [ 1 .. - 2 ] s = s . reverse if lexer . respond_to? :program and lexer . program and lexer . program . cpu and lexer . program . cpu . endianness == :little val = s . unpack ( 'C*' ) . inject ( 0 ) { | sum , c | ( sum << 8 ) | c } when :punct case tok . raw when '(' nil while ntok = lexer . readtok and ( ntok . type == :space or ntok . type == :eol ) lexer . unreadtok ntok val = parse ( lexer ) nil while ntok = lexer . readtok and ( ntok . type == :space or ntok . type == :eol ) raise tok , "syntax error, no ) found after #{val.inspect}, got #{ntok.inspect}" if not ntok or ntok . type != :punct or ntok . raw != ')' when '!' , '+' , '-' , '~' nil while ntok = lexer . readtok and ( ntok . type == :space or ntok . type == :eol ) lexer . unreadtok ntok raise tok , 'need expression after unary operator' if not val = parse_value ( lexer ) val = Expression [ tok . raw . to_sym , val ] when '.' parse_intfloat ( lexer , tok ) if not tok . value lexer . unreadtok tok return end val = tok . value else lexer . unreadtok tok return end else lexer . unreadtok tok return end nil while tok = lexer . readtok and tok . type == :space lexer . unreadtok tok val end
returns the next value from lexer (parenthesised expression, immediate, variable, unary operators)
returns the next value from lexer ( parenthesised expression immediate variable unary operators )
# ignores the 'offset' word if followed by a string # raise tok, 'need ppcessing !'
lexer