Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Maybe something for the math library... a WIP Math Parser!
#21
Quote:just google for ebnf grammars, lexer etc. you'll get a lot of info on the methods i used. it's really easy and you can add variable and constant stuff really easy and in a transparent way

After scratching my head a bit, I am beginning to see how the BNF stuff works. However, how would you add support for constants and variables? In RPN it was easy, just check each item on the stack, is a function? an operator? a number? if not it has to be a variable or constant.

I feel like the proverbal 'ol' dog'. :-)
Reply
#22
the same checking you describe is also done in the lexer ( see lex()) first you check for whitespaces and ignore them, then eol, then you check wheter it's a number, then you check for keywords, well and everything else is either a completely messed up token that doesn't follow one of the lexer rules or it's a variablename/constant. of course you have to keep track of already defined variables and constants. you could for example have such a udt

type variable
name as string * 255
expression as string * 10000
end type

type constant
name as string * 255
value as double
end type

and a datatstructure ( maybe linked list ) that keeps track of the currently in use variables and constants. you could get along with two arrays like

dim variables(MAX_VARIABLES) as variable
dim constants(MAX_CONSTANTS) as variable

so everytime you find a token that is only composed of letters and that is not a keyword you look that token up in the arrays and if you can find it either return the value along with the tokentype to the parser, or you first add that variable/constant to that arrays.

that's basically it, but uhm i'm to lazy to implement that. but it shouldn't be to hard.
quote="NecrosIhsan"]
[Image: yagl1.png]
[/quote]
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)