Skip to content

Latest commit

 

History

23 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

Program uses shunting yard algorithm to interpret C Preprocessor #if boolean expressions

  • It holds a Precedence Dictionary

Examples

  • c_eval function has a lexer, parser and eval loop
  • defined operator cannot take only a number, it must take an identifier
  • Below Expression will output a syntax error
expr = "!defined(456)"
c_eval(expr)
image
expr = "F > 12.3"
c_eval(expr)
image
expr = "!defined(AAA) && F > H +"
c_eval(expr)
image
  • If there is an identifier in this expression, it means it has not defined and treated as 0 in eval loop
  • For Example below, B will be treated as 0
expr = "!defined(B) && 123 > 1257"
c_eval(expr)
Outputs : False
  • Also FOO and F Treated as 0
expr = "!defined(FOO) && 123678 > 1257 || F + 12"
print(c_eval(expr))
Outputs : True

About

This is Python implementation of C Preprocessor (#if) conditional evaluator with lexer,parser and Shunting-Yard algorithm

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages